<?php
class Service_Blog 
{
    protected $_blogMapper;
    
    protected $_postMapper;
    
    public function __construct($blogMapper = null, $postMapper = null)
    {
        if($blogMapper === null){
            $this->setBlogMapper(new Model_BlogsMapper());
        } else {
            $this->setBlogMapper($blogMapper);
        }
        
        if($postMapper === null){
            $this->setPostMapper(new Model_PostsMapper());
        } else {
            $this->setPostMapper($postMapper);
        }
    }
    
    public function setBlogMapper($blogMapper)
    {
        $this->_blogMapper = $blogMapper;
    }
    
    public function getBlogMapper()
    {
        return $this->_blogMapper;   
    }
    
    public function setPostMapper($postMapper)
    {
        $this->_postMapper = $postMapper;  
    }
    
    public function getPostMapper()
    {
        return $this->_postMapper;    
    }
    
    public static function getInstance()
    {
        return new self();
    }
    
    public function saveBlog($blog)
    {
       return $this->_blogMapper->save($blog);
    }
    
    public function getAllBlogs()
    {
        return $this->_blogMapper->getAll();
    }
    
    public function findBlog($id)
    {
        return $this->_blogMapper->find($id);    
    }
    
    public function deleteBlog($id)
    {
        $this->_blogMapper->delete($this->findBlog($id));   
    }
}